function Y = vecparm(X,numvars,numcomp)

if isstruct(X)
        
    Y = [X.mean(:); 
         X.cov(repmat(triu(true(numvars)),[1 1 numcomp]));
         X.pr(1:end-1)'];

else

    np_mean = numvars*numcomp;
    np_cov = ((numvars^2-numvars)/2 + numvars)*numcomp;
    np_pr = numcomp - 1;

    X = mat2cell(X,[np_mean; np_cov; np_pr]);

    cov_mat = zeros([numvars numvars numcomp]);
    cov_mat(repmat(triu(true(numvars)),[1 1 numcomp])) = X{2};
    cov_mat = mat2cell(cov_mat,numvars,numvars,ones(1,numcomp));
    cov_mat = cellfun(@(x) x + triu(x,1)',cov_mat,'unif',0);

    Y = struct('mean',reshape(X{1},[numvars numcomp])...
            ,'cov',cat(3,cov_mat{:})...
            ,'pr',[X{3}' (1-sum(X{3}))]);
end

end




